﻿package plugin.roleN.controller
{
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import morn.core.handlers.*;
    import plugin.roleN.compoment.*;
    import uiresource.roleui.*;
    import view.uilt.*;
    import vo.*;

    public class BaoShiSJView extends BSshengjiUI
    {
        private var cfgGem:Array;
        private var cfgitem:Object;
        private var cfgStore:Object;
        private var _mc:XMLMovieClip;
        private var _xml1:XML;
        public static const guangyiXML:Class = BaoShiSJView_guangyiXML;

        public function BaoShiSJView()
        {
            this.cfgGem = ConfigDictionary.data.gem;
            this.cfgitem = ConfigDictionary.data.item;
            this.cfgStore = ConfigDictionary.data.storeNew;
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            yuaobaoLabel.text = "需要元宝：0";
            countLabel.isHtml = true;
            countLabel.color = 15693590;
            nameLabel.isHtml = true;
            closebtn.addEventListener(MouseEvent.CLICK, this.closeHandler);
            this._xml1 = new XML(new guangyiXML());
            App.mloader3.loadSWF(Config.getUrl("assets/images/mainui/guangyi.swf"), 1, new Handler(this.completeFunc));
            return;
        }// end function

        private function completeFunc(param1:Object) : void
        {
            this._mc = new XMLMovieClip("png.guangyi", this._xml1);
            this._mc.mouseChildren = false;
            this._mc.mouseEnabled = false;
            this._mc.visible = false;
            this._mc.x = 88 - 177;
            this._mc.y = 180 - 220;
            this._mc.play();
            this.addChild(this._mc);
            return;
        }// end function

        public function showSuccessEffect() : void
        {
            if (this._mc)
            {
                this._mc.playFromTo(-1, (this._mc.totalFrame - 1), new Handler(this.doEnd1));
                this._mc.visible = true;
            }
            return;
        }// end function

        private function doEnd1() : void
        {
            this._mc.stop();
            this._mc.visible = false;
            return;
        }// end function

        public function showItem(param1:int) : void
        {
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            this.clear();
            for each (_loc_2 in this.cfgGem)
            {
                
                if (int(_loc_2.itemid) == param1)
                {
                    _loc_3 = ItemUilt.getAllCount(param1);
                    item1.data = ItemObject.create(this.cfgitem[param1]);
                    item2.data = ItemObject.create(this.cfgitem[int(_loc_2.afterItemid)]);
                    nameLabel.text = "<font color=\'" + MColor.getqualitycolor(this.cfgitem[int(_loc_2.afterItemid)].quality) + "\'>" + this.cfgitem[int(_loc_2.afterItemid)].name + "</font>";
                    this.getText(this.cfgitem[param1], this.cfgitem[int(_loc_2.afterItemid)]);
                    if ((_loc_3 + 1) < int(_loc_2.costnum))
                    {
                        countLabel.text = "需要个数：<font color=\'#218a00\'>" + String((_loc_3 + 1)) + "/" + _loc_2.costnum + "</font>";
                        _loc_4 = this.cfgGem[param1].storeid;
                        if (checkbox.selected)
                        {
                            yuaobaoLabel.text = "需要元宝：" + String((int(_loc_2.costnum) - _loc_3) * int(this.cfgStore[_loc_4].nowprice));
                        }
                        else
                        {
                            yuaobaoLabel.text = "需要元宝：0";
                        }
                        continue;
                    }
                    countLabel.text = "需要个数：<font color=\'#218a00\'>" + String((_loc_3 + 1)) + "/" + _loc_2.costnum + "</font>";
                }
            }
            return;
        }// end function

        private function getText(param1:Object, param2:Object) : void
        {
            var _loc_3:BaoShiShengJiItem = null;
            while (panel.numChildren > 0)
            {
                
                panel.removeChildAt(0);
            }
            var _loc_4:int = 0;
            if (param2.hp > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.addText("生命上限:", param1.hp / 100 + "%", param2.hp / 100 + "%");
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                panel.addChild(_loc_3);
                _loc_4 = _loc_4 + 18;
            }
            if (param2.mp > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.addText("魔法上限:", param1.mp / 100 + "%", param2.mp / 100 + "%");
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                panel.addChild(_loc_3);
                _loc_4 = _loc_4 + 18;
            }
            if (param2.phyAttMax > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.addText("最大物攻:", param1.phyAttMax, param2.phyAttMax);
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                panel.addChild(_loc_3);
                _loc_4 = _loc_4 + 18;
            }
            if (param2.magicAtt > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.addText("最大魔攻:", param1.magicAttMax, param2.magicAttMax);
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                panel.addChild(_loc_3);
                _loc_4 = _loc_4 + 18;
            }
            if (param2.phyDef > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.addText("最大物防:", param1.phyDefMax, param2.phyDefMax);
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                panel.addChild(_loc_3);
                _loc_4 = _loc_4 + 18;
            }
            if (param2.magicDefMax > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.addText("最大魔防:", param1.magicDefMax, param2.magicDefMax);
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                panel.addChild(_loc_3);
                _loc_4 = _loc_4 + 18;
            }
            if (param2.taoAtt > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.addText("最大道攻:", param1.taoAttMax, param2.taoAttMax);
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                panel.addChild(_loc_3);
                _loc_4 = _loc_4 + 18;
            }
            if (param2.critRate > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                _loc_3.addText("暴伤::", param1.critRate, "");
                panel.addChild(_loc_3);
            }
            if (param2.critical > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                _loc_3.addText("暴击:", param2.critical / 100 + "%", "");
                panel.addChild(_loc_3);
            }
            if (param2.holyAtt > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                _loc_3.addText("神圣:", param2.holyAtt, "");
                panel.addChild(_loc_3);
            }
            if (param2.accurate > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                _loc_3.addText("准确:", param2.accurate, "");
                panel.addChild(_loc_3);
            }
            if (param2.dodge > 0)
            {
                _loc_3 = new BaoShiShengJiItem();
                _loc_3.x = 60;
                _loc_3.y = _loc_4;
                _loc_3.addText("闪避:", param2.dodge, "");
                panel.addChild(_loc_3);
            }
            return;
        }// end function

        public function clear() : void
        {
            while (panel.numChildren > 0)
            {
                
                panel.removeChildAt(0);
            }
            yuaobaoLabel.text = "需要元宝：0";
            countLabel.text = "需要：0个";
            item1.data = null;
            item2.data = null;
            nameLabel.text = "";
            return;
        }// end function

        private function closeHandler(event:MouseEvent) : void
        {
            this.visible = false;
            return;
        }// end function

    }
}
